import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/3/24 10:03
 */

public class Solution {
    public int minSubArrayLen(int target, int[] nums){
        int len = nums.length,ret = Integer.MAX_VALUE,sum = 0;
        for(int left = 0,right = 0;right < len;right++){
            sum += nums[right];
            while(sum >= target){
                ret = Math.min(ret,right - left + 1);
                sum -= nums[left++];
            }
        }
        return ret == Integer.MAX_VALUE ? 0 : ret;
    }

    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        while(in.hasNextInt()){
            int target = in.nextInt();
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            Solution solution = new Solution();
            System.out.println(solution.minSubArrayLen(target, nums));
        }
    }
}